<?php 
/**
 * Authorization page controller.
 * 
 * @author james
 *
 */
class AuthorizationController extends Zend_Controller_Action
{

	private $user;
	private $invitation;
	private $authorizationMap;
	
	public function init() {
		$this->user = new User();
		$this->invitation = new Invitation();
		$this->authorizationMap = new AuthorizationMap();
	}
	
	/**
	 * Index action.
	 * 
	 * Parameters:
	 * aid: authorization id
	 * id: invitation id
	 * key: email md5 value
	 */
	public function indexAction() {
		$key = $this->getRequest()->getParam('key');
		$authorizationMap = $this->authorizationMap->findByValue($key);
		if ($authorizationMap) {
			// send status 1 means that invited user has click the invitation link.
			$this->authorizationMap->setStatus($key, AuthorizationMap::MAIL_ACCESSED);
			$user_id = $authorizationMap->user_id;
			$invitation_id = $authorizationMap->invitation_id;
			$url = '/invitation/view/iid/'.$invitation_id.'/uid/'.$user_id.'/key/'.$key;
			$this->_redirect($url);
		} else {
			echo "Error"; exit;
			
		}
	}
}
?>